const { nanoid, customAlphabet } = require ('nanoid')

/**
 * options 配置 {
 * 
 * datas: 整体数据  或者  object
 * filterItem : 需要过滤的项
 * join:  需要拼接的项
 * 
 * } 
 * */ 
const formatToJson = (options = {})=> {
    let params = []
    let { datas, filterItem, join} = options
    for(let key in datas){
        if(filterItem.indexOf(key) === -1){
            params.push(key + '=' + `'${datas[key]}'`)
        }
    }
    let queryString = params.join(join)
    return queryString;
}
// 创建uid
const createUID = (size = 18)=> {
    let str = 'abcdefghijklmnopqrstuvwxyz1234567890'
    let uuid =  customAlphabet(str,size)
    return uuid()
}


module.exports = {
    formatToJson, 
    createUID
}